package com.ymm.spark.dao.impl;

import com.ymm.spark.config.JdbcHelper;
import com.ymm.spark.dao.ITaskDAO;
import com.ymm.spark.domain.Task;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author zhangj
 * @date 2019/10/26
 */
public class ITaskDAOImpl implements ITaskDAO {
	@Override
	public Task findById(long taskid) {
		final Task task = new Task();
		String sql = "select * from task where task_id = ?";
		Object[] params = new Object[]{taskid};
		JdbcHelper jdbcHelper = JdbcHelper.getInstance();
		jdbcHelper.executeQuery(sql, params, new JdbcHelper.QueryCallBack() {
			@Override
			public void process(ResultSet rs) throws SQLException {
				if (rs.next()) {
					long taskid = rs.getLong(1);
					String taskName = rs.getString(2);
					String createTime = rs.getString(3);
					String startTime = rs.getString(4);
					String finishTime = rs.getString(5);
					String taskType = rs.getString(6);
					String taskStatus = rs.getString(7);
					String taskParam = rs.getString(8);

					task.setTaskid(taskid);
					task.setTaskName(taskName);
					task.setCreateTime(createTime);
					task.setStartTime(startTime);
					task.setFinishTime(finishTime);
					task.setTaskType(taskType);
					task.setTaskStatus(taskStatus);
					task.setTaskParam(taskParam);
				}
			}
		});
		return task;
	}
}
